clear

import excel "Figure 2 Data.xlsx", sheet("Clean") firstrow

reshape long gdp, i(id) j(year)

save "Table 2 Data.dta", replace

set more off
set matsize 800

xtset id year, yearly

drop if year < 2012

gen post = 0 // before and after dummies
replace post = 1 if year >= 2018

gen treat_post = all_treat*post // beta3 interaction term

tabulate id, gen(id_dumm) // county dummies
tabulate year, gen(year_dumm) // year dummies

gen ln_gdp = ln(gdp)

sort id year

* county-specific time trends

bysort id: gen trend = _n

forval i = 1/77 {
	gen id_trend_dumm`i' = id_dumm`i'*trend
}

gen treat_trend = all_treat*trend

sort id year

* BORDER REGRESSIONS

* keep if border_treat == 1 | border_control == 1

* SECOND LAYER REGRESSIONS

* keep if layer_treat == 1 | layer_control == 1

* ALL COUNTIES

xtreg ln_gdp all_treat post treat_post trend treat_trend, cluster(id)

xtreg ln_gdp treat_post year_dumm* id_trend_dumm*, fe i(id) cluster(id)


